package com.ehotting.mqbd.response.config;

import com.ehotting.mqbd.api.bean.MqApplicationContext;
import com.ehotting.mqbd.api.enums.DirectionEnum;
import com.ehotting.mqbd.api.enums.TopicEnum;
import com.ehotting.mqbd.core.helper.MQStringHelper;
import com.ehotting.mqbd.core.logger.MqMsgLogger;
import com.ehotting.mqbd.core.mq.consumer.action.ConsumerResponseAction;
import com.ehotting.mqbd.core.config.MqbdCorePropertyConfig;
import com.ehotting.mqbd.core.mq.consumer.MessageConsumer;
import com.ehotting.mqbd.core.manager.ModuleManager;
import com.ehotting.mqbd.core.sync.MqSyncFutureMapHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
@DependsOn("mqbdCorePropertyConfig")
public class ConsumerActionResponseConfig {

//    @Bean(name="consumerResponseBlockAction")
//    public ConsumerResponseAction consumerResponseBlockAction(MqApplicationContext mqApplicationContext,
//                                                              MqSyncFutureMapHelper mqSyncFutureMapHelper, ModuleManager moduleManager, MqMsgLogger mqMsgLogger){
//        ConsumerResponseAction action = new ConsumerResponseAction(
//                mqSyncFutureMapHelper,
//                 mqApplicationContext,TopicEnum.BLOCK,DirectionEnum.RESPONSE, moduleManager,mqMsgLogger
//        );
//
//        return action;
//    }

    @Bean(name="consumerResponseConcurrencyAction")
    public ConsumerResponseAction consumerResponseConcurrencyAction(MqApplicationContext mqApplicationContext,
                                                                    MqSyncFutureMapHelper mqSyncFutureMapHelper, ModuleManager moduleManager, MqMsgLogger mqMsgLogger){
        ConsumerResponseAction action = new ConsumerResponseAction(
                mqSyncFutureMapHelper,
                mqApplicationContext,TopicEnum.CONCURRENCY,DirectionEnum.RESPONSE, moduleManager,mqMsgLogger);

        return action;
    }

    @Bean(name="responseConcurrencyMessageConsumer",initMethod = "start",destroyMethod = "shutdown")
    public MessageConsumer responseConcurrencyMessageConsumer(MqbdCorePropertyConfig mqbdCorePropertyConfig,
                                                              ConsumerResponseAction consumerResponseConcurrencyAction,
                                                              MqApplicationContext mqApplicationContext){
        MessageConsumer messageConsumer = new MessageConsumer(
                mqbdCorePropertyConfig.getConsumer(),
                MQStringHelper.createConsumerGroupAtConsumerApp(TopicEnum.CONCURRENCY , mqApplicationContext , DirectionEnum.RESPONSE),
                consumerResponseConcurrencyAction);

        return messageConsumer;
    }

//    @Bean(name="responseBlockMessageConsumer",initMethod = "start",destroyMethod = "shutdown")
//    public MessageConsumer responseBlockMessageConsumer(MqbdCorePropertyConfig mqbdCorePropertyConfig,
//                                                        ConsumerResponseAction consumerResponseBlockAction,
//                                                        MqApplicationContext mqApplicationContext){
//        MessageConsumer messageConsumer = new MessageConsumer(
//                mqbdCorePropertyConfig.getConsumer(),
//                MQStringHelper.createConsumerGroupAtConsumerApp(TopicEnum.BLOCK , mqApplicationContext , DirectionEnum.RESPONSE),
//                consumerResponseBlockAction);
//        return messageConsumer;
//    }

//    @Bean("moduleManager")
//    @DependsOn("mqbdCorePropertyConfig")
//    public ModuleManager moduleManager(MqbdCoreServerInfoConfig mqbdCorePropertyConfig,
//                                       RedisService redisService){
//        ModuleManager moduleManager = new ModuleManager(mqbdCorePropertyConfig,redisService);
//        return moduleManager;
//    }

}